#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //child
        int cnt = 5;
        while(cnt)
        {
            printf("child[%d] is running:cnt is %d\n" ,getpid(),cnt);
            cnt--;
            sleep(1);
        }
        exit(1);
    }
    sleep(10);
    int status = 0;
    pid_t ret = waitpid(id,&status,0);
    if(ret > 0)
    {
        if(WIFEXITED(status))
        {
            printf("exit code : %d\n",WEXITSTATUS(status));
        }
        else
        {
            printf("father wait failed!\n");
        }  
        
    }
    sleep(10);
    return 0;
}
